package com.zhang.hadoop.thrift.server;

import com.zhang.hadoop.thrift.service.impl.PersonServiceImpl;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.layered.TFramedTransport;
import thrift.generated.PersonService;

/**
 * @author: zhang yufei
 * @createTime:2022-03-27 下午 4:08
 * @description:
 */
public class ThriftServer {

    public static void main(String[] args) throws Exception{
        TNonblockingServerSocket socket=new TNonblockingServerSocket(8000);
        THsHaServer.Args arg=new THsHaServer.Args(socket).minWorkerThreads(2).maxWorkerThreads(4);
        PersonService.Processor<PersonServiceImpl> processor=new PersonService.Processor<>(new PersonServiceImpl());

        arg.protocolFactory(new TCompactProtocol.Factory());
        arg.transportFactory(new TFramedTransport.Factory());
        arg.processorFactory(new TProcessorFactory(processor));

        TServer server=new THsHaServer(arg);

        System.out.println("Thrift Server Started");

        server.serve();
    }
}
